﻿using System;
using System.Collections.Generic;
using System.Linq;
using Autodesk.Revit.DB;

namespace HYRevitCode.FaceCalculateUtility
{
	public class SplitBoxPacker
	{
		public XYZ MaxPoint
		{
			get
			{
				return this.m_maxPoint;
			}
			private set
			{
				this.m_maxPoint = value;
			}
		}

		public XYZ MinPoint
		{
			get
			{
				return this.m_minPoint;
			}
			private set
			{
				this.m_minPoint = value;
			}
		}

		public List<Line> LstBoundary
		{
			get
			{
				return this.m_lstBoundary;
			}
			private set
			{
				this.m_lstBoundary = value;
			}
		}

		internal SplitBoxPacker(XYZ inputMax, XYZ inputMin)
		{
			this.m_maxPoint = inputMax;
			this.m_minPoint = inputMin;
			List<XYZ> boxBottemPoints = SplitBoxPacker.GetBoxBottemPoints(inputMax, inputMin);
			List<Line> list = new List<Line>();
			for (int i = 0; i < boxBottemPoints.Count - 1; i++)
			{
				Line item = Line.CreateBound(boxBottemPoints[i], boxBottemPoints[i + 1]);
				list.Add(item);
			}
			Line item2 = Line.CreateBound(boxBottemPoints.Last<XYZ>(), boxBottemPoints.First<XYZ>());
			list.Add(item2);
			this.LstBoundary = list;
		}

		internal static List<XYZ> GetBoxBottemPoints(XYZ inputMax, XYZ inputMin)
		{
			XYZ xyz = new XYZ(inputMax.X, inputMax.Y, inputMin.Z);
			XYZ xyzpoint = Line.CreateUnbound(inputMin, XYZ.BasisY).Project(xyz).XYZPoint;
			XYZ xyzpoint2 = Line.CreateUnbound(xyz, XYZ.BasisY).Project(inputMin).XYZPoint;
			return new List<XYZ>
			{
				inputMin,
				xyzpoint2,
				xyz,
				xyzpoint
			};
		}

		private XYZ m_maxPoint;

		private XYZ m_minPoint;

		private List<Line> m_lstBoundary = new List<Line>();
	}
}
